package com.flying.refdata;


import com.flying.common.CommonApplication;
import com.flying.refdata.batchload.FileUploader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.Arrays;

@SpringBootApplication(scanBasePackageClasses = {CommonApplication.class, DataImporter.class})
public class DataImporter implements CommandLineRunner {
    private static final Logger logger = LoggerFactory.getLogger(DataImporter.class);
    @Autowired
    private FileUploader uploader;
    @Autowired
    private ThreadPoolTaskExecutor executor;

    @Override
    public void run(String... args) {
        try {
            for (String fileName : args) {
                uploader.upload(fileName);
            }
        } catch (Throwable t) {
            logger.error("Throwable occurs:" + Arrays.toString(args), t);
        }
        executor.shutdown();
    }

    public static void main(String[] args) {
        SpringApplication.run(DataImporter.class, args);
    }
}